package com.atguigu.gmall.all.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.TemplateEngine;

@Controller
@RequestMapping
public class IndexController {

    @Autowired
    private ProductFeignClient productFeignClient;
    @Autowired
    private TemplateEngine templateEngine;

    @GetMapping("/")
    public String index(Model model){

        Result result = productFeignClient.getBaseCategoryList();
        model.addAttribute("list",result.getData());

        return "index/index";
    }
//    @GetMapping("/")
//    public String index(){
//        return "index";
//    }
//    @GetMapping("/createHtml")
//    @ResponseBody
//    public Result createHtml() throws Exception{
//        Result result = productFeignClient.getBaseCategoryList();
//
//        Context context = new Context();
//        context.setVariable("list",result.getData());
//        Writer out = new FileWriter("D:\\temp\\index.html");
//        templateEngine.process("index/index",context,out);
//
//        return Result.ok();
//    }
}
